home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / gr564s.zip / SRC / RCSREV.C < prev    next >
C/C++ Source or Header  |  1992-09-05  |  21KB  |  798 lines

  1. /*
  2.  *                     RCS revision number handling
  3.  */
  4.  
  5. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  6.    Copyright 1990, 1991, 1992 by Paul Eggert
  7.    Distributed under license by the Free Software Foundation, Inc.
  8.  
  9. This file is part of RCS.
  10.  
  11. RCS is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2, or (at your option)
  14. any later version.
  15.  
  16. RCS is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with RCS; see the file COPYING.  If not, write to
  23. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25. Report problems and direct all questions to:
  26.  
  27.     rcs-bugs@cs.purdue.edu
  28.  
  29. */
  30.  
  31.  
  32.  
  33.  
  34. /* $Log: rcsrev.c,v $
  35.  * Revision 5.5  1992/07/28  16:12:44  eggert
  36.  * Identifiers may now start with a digit.  Avoid `unsigned'.
  37.  *
  38.  * Revision 5.4  1992/01/06  02:42:34  eggert
  39.  * while (E) ; -> while (E) continue;
  40.  *
  41.  * Revision 5.3  1991/08/19  03:13:55  eggert
  42.  * Add `-r$', `-rB.'.  Remove botches like `<now>' from messages.  Tune.
  43.  *
  44.  * Revision 5.2  1991/04/21  11:58:28  eggert
  45.  * Add tiprev().
  46.  *
  47.  * Revision 5.1  1991/02/25  07:12:43  eggert
  48.  * Avoid overflow when comparing revision numbers.
  49.  *
  50.  * Revision 5.0  1990/08/22  08:13:43  eggert
  51.  * Remove compile-time limits; use malloc instead.
  52.  * Ansify and Posixate.  Tune.
  53.  * Remove possibility of an internal error.  Remove lint.
  54.  *
  55.  * Revision 4.5  89/05/01  15:13:22  narten
  56.  * changed copyright header to reflect current distribution rules
  57.  * 
  58.  * Revision 4.4  87/12/18  11:45:22  narten
  59.  * more lint cleanups. Also, the NOTREACHED comment is no longer necessary, 
  60.  * since there's now a return value there with a value. (Guy Harris)
  61.  * 
  62.  * Revision 4.3  87/10/18  10:38:42  narten
  63.  * Updating version numbers. Changes relative to version 1.1 actually 
  64.  * relative to 4.1
  65.  * 
  66.  * Revision 1.3  87/09/24  14:00:37  narten
  67.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  68.  * warnings)
  69.  * 
  70.  * Revision 1.2  87/03/27  14:22:37  jenkins
  71.  * Port to suns
  72.  * 
  73.  * Revision 4.1  83/03/25  21:10:45  wft
  74.  * Only changed $Header to $Id.
  75.  * 
  76.  * Revision 3.4  82/12/04  13:24:08  wft
  77.  * Replaced getdelta() with gettree().
  78.  *
  79.  * Revision 3.3  82/11/28  21:33:15  wft
  80.  * fixed compartial() and compnum() for nil-parameters; fixed nils
  81.  * in error messages. Testprogram output shortenend.
  82.  *
  83.  * Revision 3.2  82/10/18  21:19:47  wft
  84.  * renamed compnum->cmpnum, compnumfld->cmpnumfld,
  85.  * numericrevno->numricrevno.
  86.  *
  87.  * Revision 3.1  82/10/11  19:46:09  wft
  88.  * changed expandsym() to check for source==nil; returns zero length string
  89.  * in that case.
  90.  */
  91.  
  92.  
  93.  
  94. /*
  95. #define REVTEST
  96. */
  97. /* version REVTEST is for testing the routines that generate a sequence
  98.  * of delta numbers needed to regenerate a given delta.
  99.  */
  100.  
  101. #include "rcsbase.h"
  102.  
  103. libId(revId, "$Id: rcsrev.c,v 5.5 1992/07/28 16:12:44 eggert Exp $")
  104.  
  105. static char const *branchtip P((char const*));
  106. static struct hshentry *genbranch P((struct hshentry const*,char const*,int,char const*,char const*,char const*,struct hshentries**));
  107.  
  108.  
  109.  
  110.     int
  111. countnumflds(s)
  112.     char const *s;
  113. /* Given a pointer s to a dotted number (date or revision number),
  114.  * countnumflds returns the number of digitfields in s.
  115.  */
  116. {
  117.     register char const *sp;
  118.     register int count;
  119.         if ((sp=s)==nil) return(0);
  120.         if (*sp == '\0') return(0);
  121.         count = 1;
  122.     do {
  123.                 if (*sp++ == '.') count++;
  124.     } while (*sp);
  125.         return(count);
  126. }
  127.  
  128.     void
  129. getbranchno(revno,branchno)
  130.     char const *revno;
  131.     struct buf *branchno;
  132. /* Given a non-nil revision number revno, getbranchno copies the number of the branch
  133.  * on which revno is into branchno. If revno itself is a branch number,
  134.  * it is copied unchanged.
  135.  */
  136. {
  137.     register int numflds;
  138.     register char *tp;
  139.  
  140.     bufscpy(branchno, revno);
  141.         numflds=countnumflds(revno);
  142.     if (!(numflds & 1)) {
  143.         tp = branchno->string;
  144.         while (--numflds)
  145.             while (*tp++ != '.')
  146.                 continue;
  147.                 *(tp-1)='\0';
  148.         }
  149. }
  150.  
  151.  
  152.  
  153. int cmpnum(num1, num2)
  154.     char const *num1, *num2;
  155. /* compares the two dotted numbers num1 and num2 lexicographically
  156.  * by field. Individual fields are compared numerically.
  157.  * returns <0, 0, >0 if num1<num2, num1==num2, and num1>num2, resp.
  158.  * omitted fields are assumed to be higher than the existing ones.
  159. */
  160. {
  161.     register char const *s1, *s2;
  162.     register size_t d1, d2;
  163.     register int r;
  164.  
  165.         s1=num1==nil?"":num1;
  166.         s2=num2==nil?"":num2;
  167.  
  168.     for (;;) {
  169.         /* Give precedence to shorter one.  */
  170.         if (!*s1)
  171.             return (unsigned char)*s2;
  172.         if (!*s2)
  173.             return -1;
  174.  
  175.         /* Strip leading zeros, then find number of digits.  */
  176.         while (*s1=='0') ++s1;
  177.         while (*s2=='0') ++s2;
  178.         for (d1=0; isdigit(s1[d1]); d1++) continue;
  179.         for (d2=0; isdigit(s2[d2]); d2++) continue;
  180.  
  181.         /* Do not convert to integer; it might overflow!  */
  182.         if (d1 != d2)
  183.             return d1<d2 ? -1 : 1;
  184.         if ((r = memcmp(s1, s2, d1)))
  185.             return r;
  186.         s1 += d1;
  187.         s2 += d1;
  188.  
  189.                 /* skip '.' */
  190.         if (*s1) s1++;
  191.         if (*s2) s2++;
  192.     }
  193. }
  194.  
  195.  
  196.  
  197. int cmpnumfld(num1, num2, fld)
  198.     char const *num1, *num2;
  199.     int fld;
  200. /* Compare the two dotted numbers at field fld.
  201.  * num1 and num2 must have at least fld fields.
  202.  * fld must be positive.
  203. */
  204. {
  205.     register char const *s1, *s2;
  206.     register size_t d1, d2;
  207.  
  208.     s1 = num1;
  209.     s2 = num2;
  210.         /* skip fld-1 fields */
  211.     while (--fld) {
  212.         while (*s1++ != '.')
  213.             continue;
  214.         while (*s2++ != '.')
  215.             continue;
  216.     }
  217.         /* Now s1 and s2 point to the beginning of the respective fields */
  218.     while (*s1=='0') ++s1;  for (d1=0; isdigit(s1[d1]); d1++) continue;
  219.     while (*s2=='0') ++s2;  for (d2=0; isdigit(s2[d2]); d2++) continue;
  220.  
  221.     return d1<d2 ? -1 : d1==d2 ? memcmp(s1,s2,d1) : 1;
  222. }
  223.  
  224.  
  225.     static void
  226. cantfindbranch(revno, date, author, state)
  227.     char const *revno, date[datesize], *author, *state;
  228. {
  229.     char datebuf[datesize];
  230.  
  231.     error("No revision on branch %s has%s%s%s%s%s%s.",
  232.         revno,
  233.         date ? " a date before " : "",
  234.         date ? date2str(date,datebuf) : "",
  235.         author ? " and author "+(date?0:4) : "",
  236.         author ? author : "",
  237.         state ? " and state "+(date||author?0:4) : "",
  238.         state ? state : ""
  239.     );
  240. }
  241.  
  242.     static void
  243. absent(revno, field)
  244.     char const *revno;
  245.     int field;
  246. {
  247.     struct buf t;
  248.     bufautobegin(&t);
  249.     error("%s %s absent", field&1?"revision":"branch",
  250.         partialno(&t,revno,field)
  251.     );
  252.     bufautoend(&t);
  253. }
  254.  
  255.  
  256.     int
  257. compartial(num1, num2, length)
  258.     char const *num1, *num2;
  259.     int length;
  260.  
  261. /*   compare the first "length" fields of two dot numbers;
  262.      the omitted field is considered to be larger than any number  */
  263. /*   restriction:  at least one number has length or more fields   */
  264.  
  265. {
  266.     register char const *s1, *s2;
  267.     register size_t d1, d2;
  268.     register int r;
  269.  
  270.         s1 = num1;      s2 = num2;
  271.     if (!s1) return 1;
  272.     if (!s2) return -1;
  273.  
  274.     for (;;) {
  275.         if (!*s1) return 1;
  276.         if (!*s2) return -1;
  277.  
  278.         while (*s1=='0') ++s1;  for (d1=0; isdigit(s1[d1]); d1++) continue;
  279.         while (*s2=='0') ++s2;  for (d2=0; isdigit(s2[d2]); d2++) continue;
  280.  
  281.         if (d1 != d2)
  282.             return d1<d2 ? -1 : 1;
  283.         if ((r = memcmp(s1, s2, d1)))
  284.             return r;
  285.         s1 += d1;
  286.         s2 += d1;
  287.  
  288.         if (*s1 == '.') s1++;
  289.             if (*s2 == '.') s2++;
  290.  
  291.         if ( --length == 0 ) return 0;
  292.     }
  293. }
  294.  
  295.  
  296. char * partialno(rev1,rev2,length)
  297.     struct buf *rev1;
  298.     char const *rev2;
  299.     register int length;
  300. /* Function: Copies length fields of revision number rev2 into rev1.
  301.  * Return rev1's string.
  302.  */
  303. {
  304.     register char *r1;
  305.  
  306.     bufscpy(rev1, rev2);
  307.     r1 = rev1->string;
  308.         while (length) {
  309.         while (*r1!='.' && *r1)
  310.             ++r1;
  311.         ++r1;
  312.                 length--;
  313.         }
  314.         /* eliminate last '.'*/
  315.         *(r1-1)='\0';
  316.     return rev1->string;
  317. }
  318.  
  319.  
  320.  
  321.  
  322.     static void
  323. store1(store, next)
  324.     struct hshentries ***store;
  325.     struct hshentry *next;
  326. /*
  327.  * Allocate a new list node that addresses NEXT.
  328.  * Append it to the list that **STORE is the end pointer of.
  329.  */
  330. {
  331.     register struct hshentries *p;
  332.  
  333.     p = ftalloc(struct hshentries);
  334.     p->first = next;
  335.     **store = p;
  336.     *store = &p->rest;
  337. }
  338.  
  339. struct hshentry * genrevs(revno,date,author,state,store)
  340.     char const *revno, *date, *author, *state;
  341.     struct hshentries **store;
  342. /* Function: finds the deltas needed for reconstructing the
  343.  * revision given by revno, date, author, and state, and stores pointers
  344.  * to these deltas into a list whose starting address is given by store.
  345.  * The last delta (target delta) is returned.
  346.  * If the proper delta could not be found, nil is returned.
  347.  */
  348. {
  349.     int length;
  350.         register struct hshentry * next;
  351.         int result;
  352.     char const *branchnum;
  353.     struct buf t;
  354.     char datebuf[datesize];
  355.  
  356.     bufautobegin(&t);
  357.  
  358.     if (!(next = Head)) {
  359.         error("RCS file empty");
  360.         goto norev;
  361.         }
  362.  
  363.         length = countnumflds(revno);
  364.  
  365.         if (length >= 1) {
  366.                 /* at least one field; find branch exactly */
  367.         while ((result=cmpnumfld(revno,next->num,1)) < 0) {
  368.             store1(&store, next);
  369.                         next = next->next;
  370.             if (!next) {
  371.                 error("branch number %s too low", partialno(&t,revno,1));
  372.                 goto norev;
  373.             }
  374.                 }
  375.  
  376.         if (result>0) {
  377.             absent(revno, 1);
  378.             goto norev;
  379.         }
  380.         }
  381.         if (length<=1){
  382.                 /* pick latest one on given branch */
  383.                 branchnum = next->num; /* works even for empty revno*/
  384.                 while ((next!=nil) &&
  385.                        (cmpnumfld(branchnum,next->num,1)==0) &&
  386.                        !(
  387.                         (date==nil?1:(cmpnum(date,next->date)>=0)) &&
  388.                         (author==nil?1:(strcmp(author,next->author)==0)) &&
  389.                         (state ==nil?1:(strcmp(state, next->state) ==0))
  390.                         )
  391.                        )
  392.         {
  393.             store1(&store, next);
  394.                         next=next->next;
  395.                 }
  396.                 if ((next==nil) ||
  397.                     (cmpnumfld(branchnum,next->num,1)!=0))/*overshot*/ {
  398.             cantfindbranch(
  399.                 length ? revno : partialno(&t,branchnum,1),
  400.                 date, author, state
  401.             );
  402.             goto norev;
  403.                 } else {
  404.             store1(&store, next);
  405.                 }
  406.                 *store = nil;
  407.                 return next;
  408.         }
  409.  
  410.         /* length >=2 */
  411.         /* find revision; may go low if length==2*/
  412.     while ((result=cmpnumfld(revno,next->num,2)) < 0  &&
  413.                (cmpnumfld(revno,next->num,1)==0) ) {
  414.         store1(&store, next);
  415.                 next = next->next;
  416.         if (!next)
  417.             break;
  418.         }
  419.  
  420.         if ((next==nil) || (cmpnumfld(revno,next->num,1)!=0)) {
  421.         error("revision number %s too low", partialno(&t,revno,2));
  422.         goto norev;
  423.         }
  424.         if ((length>2) && (result!=0)) {
  425.         absent(revno, 2);
  426.         goto norev;
  427.         }
  428.  
  429.         /* print last one */
  430.     store1(&store, next);
  431.  
  432.         if (length>2)
  433.                 return genbranch(next,revno,length,date,author,state,store);
  434.         else { /* length == 2*/
  435.                 if ((date!=nil) && (cmpnum(date,next->date)<0)){
  436.             error("Revision %s has date %s.",
  437.                 next->num,
  438.                 date2str(next->date, datebuf)
  439.             );
  440.                         return nil;
  441.                 }
  442.                 if ((author!=nil)&&(strcmp(author,next->author)!=0)) {
  443.                         error("Revision %s has author %s.",next->num,next->author);
  444.                         return nil;
  445.                 }
  446.                 if ((state!=nil)&&(strcmp(state,next->state)!=0)) {
  447.                         error("Revision %s has state %s.",next->num,
  448.                                next->state==nil?"<empty>":next->state);
  449.                         return nil;
  450.                 }
  451.                 *store=nil;
  452.                 return next;
  453.         }
  454.  
  455.     norev:
  456.     bufautoend(&t);
  457.     return nil;
  458. }
  459.  
  460.  
  461.  
  462.  
  463.     static struct hshentry *
  464. genbranch(bpoint, revno, length, date, author, state, store)
  465.     struct hshentry const *bpoint;
  466.     char const *revno;
  467.     int length;
  468.     char const *date, *author, *state;
  469.     struct hshentries **store;
  470. /* Function: given a branchpoint, a revision number, date, author, and state,
  471.  * genbranch finds the deltas necessary to reconstruct the given revision
  472.  * from the branch point on.
  473.  * Pointers to the found deltas are stored in a list beginning with store.
  474.  * revno must be on a side branch.
  475.  * return nil on error
  476.  */
  477. {
  478.     int field;
  479.         register struct hshentry * next, * trail;
  480.     register struct branchhead const *bhead;
  481.         int result;
  482.     struct buf t;
  483.     char datebuf[datesize];
  484.  
  485.     field = 3;
  486.         bhead = bpoint->branches;
  487.  
  488.     do {
  489.         if (!bhead) {
  490.             bufautobegin(&t);
  491.             error("no side branches present for %s", partialno(&t,revno,field-1));
  492.             bufautoend(&t);
  493.             return nil;
  494.         }
  495.  
  496.                 /*find branch head*/
  497.                 /*branches are arranged in increasing order*/
  498.         while (0 < (result=cmpnumfld(revno,bhead->hsh->num,field))) {
  499.                         bhead = bhead->nextbranch;
  500.             if (!bhead) {
  501.                 bufautobegin(&t);
  502.                 error("branch number %s too high",partialno(&t,revno,field));
  503.                 bufautoend(&t);
  504.                 return nil;
  505.             }
  506.                 }
  507.  
  508.         if (result<0) {
  509.             absent(revno, field);
  510.             return nil;
  511.         }
  512.  
  513.                 next = bhead->hsh;
  514.                 if (length==field) {
  515.                         /* pick latest one on that branch */
  516.                         trail=nil;
  517.                         do { if ((date==nil?1:(cmpnum(date,next->date)>=0)) &&
  518.                                  (author==nil?1:(strcmp(author,next->author)==0)) &&
  519.                                  (state ==nil?1:(strcmp(state, next->state) ==0))
  520.                              ) trail = next;
  521.                              next=next->next;
  522.                         } while (next!=nil);
  523.  
  524.                         if (trail==nil) {
  525.                  cantfindbranch(revno, date, author, state);
  526.                              return nil;
  527.                         } else { /* print up to last one suitable */
  528.                              next = bhead->hsh;
  529.                              while (next!=trail) {
  530.                   store1(&store, next);
  531.                                   next=next->next;
  532.                              }
  533.                  store1(&store, next);
  534.                         }
  535.             *store = nil;
  536.                         return next;
  537.                 }
  538.  
  539.                 /* length > field */
  540.                 /* find revision */
  541.                 /* check low */
  542.                 if (cmpnumfld(revno,next->num,field+1)<0) {
  543.             bufautobegin(&t);
  544.             error("revision number %s too low", partialno(&t,revno,field+1));
  545.             bufautoend(&t);
  546.                         return(nil);
  547.                 }
  548.         do {
  549.             store1(&store, next);
  550.                         trail = next;
  551.                         next = next->next;
  552.                 } while ((next!=nil) &&
  553.                        (cmpnumfld(revno,next->num,field+1) >=0));
  554.  
  555.                 if ((length>field+1) &&  /*need exact hit */
  556.                     (cmpnumfld(revno,trail->num,field+1) !=0)){
  557.             absent(revno, field+1);
  558.                         return(nil);
  559.                 }
  560.                 if (length == field+1) {
  561.                         if ((date!=nil) && (cmpnum(date,trail->date)<0)){
  562.                 error("Revision %s has date %s.",
  563.                     trail->num,
  564.                     date2str(trail->date, datebuf)
  565.                 );
  566.                                 return nil;
  567.                         }
  568.                         if ((author!=nil)&&(strcmp(author,trail->author)!=0)) {
  569.                                 error("Revision %s has author %s.",trail->num,trail->author);
  570.                                 return nil;
  571.                         }
  572.                         if ((state!=nil)&&(strcmp(state,trail->state)!=0)) {
  573.                                 error("Revision %s has state %s.",trail->num,
  574.                                        trail->state==nil?"<empty>":trail->state);
  575.                                 return nil;
  576.                         }
  577.                 }
  578.                 bhead = trail->branches;
  579.  
  580.     } while ((field+=2) <= length);
  581.         * store = nil;
  582.         return trail;
  583. }
  584.  
  585.  
  586.     static char const *
  587. lookupsym(id)
  588.     char const *id;
  589. /* Function: looks up id in the list of symbolic names starting
  590.  * with pointer SYMBOLS, and returns a pointer to the corresponding
  591.  * revision number. Returns nil if not present.
  592.  */
  593. {
  594.     register struct assoc const *next;
  595.         next = Symbols;
  596.         while (next!=nil) {
  597.                 if (strcmp(id, next->symbol)==0)
  598.             return next->num;
  599.                 else    next=next->nextassoc;
  600.         }
  601.         return nil;
  602. }
  603.  
  604. int expandsym(source, target)
  605.     char const *source;
  606.     struct buf *target;
  607. /* Function: Source points to a revision number. Expandsym copies
  608.  * the number to target, but replaces all symbolic fields in the
  609.  * source number with their numeric values.
  610.  * Expand a branch followed by `.' to the latest revision on that branch.
  611.  * Ignore `.' after a revision.  Remove leading zeros.
  612.  * returns false on error;
  613.  */
  614. {
  615.     return fexpandsym(source, target, (RILE*)0);
  616. }
  617.  
  618.     int
  619. fexpandsym(source, target, fp)
  620.     char const *source;
  621.     struct buf *target;
  622.     RILE *fp;
  623. /* Same as expandsym, except if FP is nonzero, it is used to expand KDELIM.  */
  624. {
  625.     register char const *sp, *bp;
  626.     register char *tp;
  627.     char const *tlim;
  628.     int dots;
  629.  
  630.     sp = source;
  631.     bufalloc(target, 1);
  632.     tp = target->string;
  633.     if (!sp || !*sp) { /*accept nil pointer as a legal value*/
  634.                 *tp='\0';
  635.                 return true;
  636.         }
  637.     if (sp[0] == KDELIM  &&  !sp[1]) {
  638.         if (!getoldkeys(fp))
  639.             return false;
  640.         if (!*prevrev.string) {
  641.             error("working file lacks revision number");
  642.             return false;
  643.         }
  644.         bufscpy(target, prevrev.string);
  645.         return true;
  646.     }
  647.     tlim = tp + target->size;
  648.     dots = 0;
  649.  
  650.     for (;;) {
  651.         register char *p = tp;
  652.         size_t s = tp - target->string;
  653.         int id = false;
  654.         for (;;) {
  655.             switch (ctab[(unsigned char)*sp]) {
  656.             case IDCHAR:
  657.             case LETTER:
  658.             case Letter:
  659.                 id = true;
  660.                 /* fall into */
  661.             case DIGIT:
  662.                 if (tlim <= p)
  663.                     p = bufenlarge(target, &tlim);
  664.                 *p++ = *sp++;
  665.                 continue;
  666.             }
  667.             break;
  668.         }
  669.         if (tlim <= p)
  670.             p = bufenlarge(target, &tlim);
  671.         *p = 0;
  672.         tp = target->string + s;
  673.  
  674.         if (id) {
  675.             bp = lookupsym(tp);
  676.                         if (bp==nil) {
  677.                 error("Symbolic number %s is undefined.", tp);
  678.                                 return false;
  679.                         }
  680.         } else {
  681.             /* skip leading zeros */
  682.             for (bp = tp;  *bp=='0' && isdigit(bp[1]);  bp++)
  683.                 continue;
  684.  
  685.             if (!*bp)
  686.                 break;
  687.         }
  688.  
  689.         while ((*tp++ = *bp++))
  690.             if (tlim <= tp)
  691.                 tp = bufenlarge(target, &tlim);
  692.  
  693.         switch (*sp++) {
  694.             case '\0':
  695.             return true;
  696.  
  697.             case '.':
  698.             if (!*sp) {
  699.                 if (dots & 1)
  700.                     break;
  701.                 if (!(bp = branchtip(target->string)))
  702.                     return false;
  703.                 bufscpy(target, bp);
  704.                 return true;
  705.             }
  706.             ++dots;
  707.             tp[-1] = '.';
  708.             continue;
  709.         }
  710.         break;
  711.         }
  712.  
  713.     error("improper revision number: %s", source);
  714.     return false;
  715. }
  716.  
  717.     static char const *
  718. branchtip(branch)
  719.     char const *branch;
  720. {
  721.     struct hshentry *h;
  722.     struct hshentries *hs;
  723.  
  724.     h  =  genrevs(branch, (char*)0, (char*)0, (char*)0, &hs);
  725.     return h ? h->num : (char const*)0;
  726. }
  727.  
  728.     char const *
  729. tiprev()
  730. {
  731.     return Dbranch ? branchtip(Dbranch) : Head ? Head->num : (char const*)0;
  732. }
  733.  
  734.  
  735.  
  736. #ifdef REVTEST
  737.  
  738. char const cmdid[] = "revtest";
  739.  
  740.     int
  741. main(argc,argv)
  742. int argc; char * argv[];
  743. {
  744.     static struct buf numricrevno;
  745.     char symrevno[100];       /* used for input of revision numbers */
  746.         char author[20];
  747.         char state[20];
  748.         char date[20];
  749.     struct hshentries *gendeltas;
  750.         struct hshentry * target;
  751.         int i;
  752.  
  753.         if (argc<2) {
  754.         aputs("No input file\n",stderr);
  755.         exitmain(EXIT_FAILURE);
  756.         }
  757.     if (!(finptr=Iopen(argv[1], FOPEN_R, (struct stat*)0))) {
  758.         faterror("can't open input file %s", argv[1]);
  759.         }
  760.         Lexinit();
  761.         getadmin();
  762.  
  763.         gettree();
  764.  
  765.         getdesc(false);
  766.  
  767.         do {
  768.                 /* all output goes to stderr, to have diagnostics and       */
  769.                 /* errors in sequence.                                      */
  770.         aputs("\nEnter revision number or <return> or '.': ",stderr);
  771.         if (!gets(symrevno)) break;
  772.                 if (*symrevno == '.') break;
  773.         aprintf(stderr,"%s;\n",symrevno);
  774.         expandsym(symrevno,&numricrevno);
  775.         aprintf(stderr,"expanded number: %s; ",numricrevno.string);
  776.         aprintf(stderr,"Date: ");
  777.         gets(date); aprintf(stderr,"%s; ",date);
  778.         aprintf(stderr,"Author: ");
  779.         gets(author); aprintf(stderr,"%s; ",author);
  780.         aprintf(stderr,"State: ");
  781.         gets(state); aprintf(stderr, "%s;\n", state);
  782.         target = genrevs(numricrevno.string, *date?date:(char *)nil, *author?author:(char *)nil,
  783.                  *state?state:(char*)nil, &gendeltas);
  784.                 if (target!=nil) {
  785.             while (gendeltas) {
  786.                 aprintf(stderr,"%s\n",gendeltas->first->num);
  787.                 gendeltas = gendeltas->next;
  788.                         }
  789.                 }
  790.         } while (true);
  791.     aprintf(stderr,"done\n");
  792.     exitmain(EXIT_SUCCESS);
  793. }
  794.  
  795. exiting void exiterr() { _exit(EXIT_FAILURE); }
  796.  
  797. #endif
  798.